
package tetris.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * The game over dialog box.
 * 
 * @author Agari NLN (agarin@uw.edu)
 * @version 2.8
 *
 */
public class GameOver extends JDialog implements ActionListener
{
  /**
   * To avoid warnings.
   */
  private static final long serialVersionUID = 1L;

  /**
   * The method to create a dialog box to inform user the game is over.
   * @param the_parent the parent frame.
   * @param the_title the name of the dialog box
   * @param the_message the actual message displayed on the box
   */
  public GameOver(final JFrame the_parent, final String the_title, final String the_message)
  {
    super(the_parent, the_title, true);
    if (the_parent != null)
    { 
      final Dimension parentSize = the_parent.getSize();
      final Point p = the_parent.getLocation();
      setLocation(p.x + parentSize.width , p.y + parentSize.height);

    }
    
    final JPanel messagePane = new JPanel();
    messagePane.add(new JLabel(the_message));
    getContentPane().add(messagePane);
    final JPanel buttonPane = new JPanel();
    final JButton button = new JButton("O.K");
    
    buttonPane.add(button);
    button.addActionListener(this);
    getContentPane().add(buttonPane, BorderLayout.SOUTH);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    pack();
    setVisible(true);
  }

  /**
   * Bring up a pop-up window to inform user the game is over.
   * @param the_event does nothing.
   */
  public void actionPerformed(final ActionEvent the_event)
  {
    setVisible(false);
    dispose();
  }
}
